package com.huawei.gamebox.service.common.cardkit.card;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.n;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSView;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.gamebox.service.common.cardkit.bean.HorizonBaseBean;
import o.cgz;
import o.chc;
import o.chy;
import o.ContentManager;
import o.eix;
import o.eiy;
import o.MinimumFactory;
import o.evx;
import o.exp.d;

public abstract class HorizonBaseCard extends BaseGsCard {
    private CSSRule ʻ;
    private LinearLayoutManager ʼ;
    private View ʽ;
    public eix ˊ = new eix();
    private RecyclerView ˋ;
    protected androidx.recyclerview.widget.RecyclerView.a ˎ;
    public int ˏ = 2;
    public chy ॱ;

    public abstract class a extends androidx.recyclerview.widget.RecyclerView.a<b> {
        final /* synthetic */ HorizonBaseCard ˏ;

        public class b extends s {
            protected View ʻॱ;
            final /* synthetic */ a ॱᐝ;

            public b(a aVar, View view) {
                this.ॱᐝ = aVar;
                super(view);
                this.ʻॱ = view;
            }
        }

        protected abstract void ˋ(b bVar, int i);

        protected abstract b ॱ(ViewGroup viewGroup, int i);

        protected a(HorizonBaseCard horizonBaseCard) {
            this.ˏ = horizonBaseCard;
        }

        @NonNull
        public /* synthetic */ s ˎ(@NonNull ViewGroup viewGroup, int i) {
            return ˏ(viewGroup, i);
        }

        public /* synthetic */ void ॱ(@NonNull s sVar, int i) {
            ˊ((b) sVar, i);
        }

        @NonNull
        public b ˏ(@NonNull ViewGroup viewGroup, int i) {
            b ॱ = ॱ(viewGroup, i);
            if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                ॱ.ʻॱ.setLayoutDirection(1);
            }
            this.ˏ.ˋ(ॱ.ʻॱ, this.ˏ.ʻ);
            return ॱ;
        }

        public void ˊ(@NonNull b bVar, int i) {
            ˋ(bVar, i);
            MarginLayoutParams marginLayoutParams = (MarginLayoutParams) bVar.ʻॱ.getLayoutParams();
            if (marginLayoutParams != null) {
                ˏ(i, marginLayoutParams);
                bVar.ʻॱ.setLayoutParams(marginLayoutParams);
            }
        }

        private void ˏ(int i, MarginLayoutParams marginLayoutParams) {
            marginLayoutParams.setMarginEnd(0);
            if (i == 0) {
                marginLayoutParams.setMarginStart(this.ˏ.ˊ.ॱ());
                return;
            }
            if (i == ˏ() - 1) {
                marginLayoutParams.setMarginEnd(this.ˏ.ˊ.ॱ());
            }
            marginLayoutParams.setMarginStart(this.ˏ.ˊ.ॱॱ());
        }
    }

    protected abstract void ʻ();

    protected abstract androidx.recyclerview.widget.RecyclerView.a ˊॱ();

    public /* synthetic */ cgz ˏ(View view) {
        return ॱ(view);
    }

    public HorizonBaseCard(Context context) {
        super(context);
        int ˋ = chc.ˋ();
        this.ˊ.ˎ(chc.ˏ() - ˋ);
        this.ˊ.ᐝ(ˋ);
        ʻ();
    }

    public void ˊ(CSSRule cSSRule) {
        this.ʻ = cSSRule;
    }

    public View ˊ() {
        return this.ʽ;
    }

    public BaseGsCard ॱ(View view) {
        ʽ(view);
        this.ʽ = view.findViewById(d.ꜟ);
        ˋ((RecyclerView) view.findViewById(d.ˋ));
        this.ˎ = ˊॱ();
        this.ʼ = new LinearLayoutManager(view.getContext(), 0, false);
        ˎ().setLayoutManager(this.ʼ);
        if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            ˎ().setLayoutDirection(0);
            this.ʼ.ˊ(true);
        }
        ˎ().setAdapter(this.ˎ);
        new eiy().ˏ(ˎ());
        this.ˋ.ॱ(new n(this) {
            final /* synthetic */ HorizonBaseCard ॱ;

            {
                this.ॱ = r1;
            }

            public void ˎ(RecyclerView recyclerView, int i) {
                if (i == 0) {
                    CardBean ˌ = this.ॱ.ˌ();
                    if (ˌ instanceof HorizonBaseBean) {
                        HorizonBaseBean horizonBaseBean = (HorizonBaseBean) ˌ;
                        Object obj = this.ॱ.ʼ.ॱˎ() == this.ॱ.ʼ.ˌ() + -1 ? 1 : null;
                        int ॱˎ = this.ॱ.ʼ.ॱˎ();
                        this.ॱ.ˊ.ॱॱ(this.ॱ.ʼ.ॱˊ());
                        this.ॱ.ˊ.ʻ(this.ॱ.ˎ().getLeft());
                        if (obj != null) {
                            horizonBaseBean.ॱ(ॱˎ);
                            horizonBaseBean.ˏ(this.ॱ.ˊ.ʻ());
                            return;
                        }
                        horizonBaseBean.ˏ(this.ॱ.ˊ.ʻ());
                        horizonBaseBean.ॱ(this.ॱ.ˊ.ᐝ());
                    }
                }
            }
        });
        return this;
    }

    public RecyclerView ˎ() {
        return this.ˋ;
    }

    public void ˋ(RecyclerView recyclerView) {
        this.ˋ = recyclerView;
    }

    public chy ˋ() {
        return this.ॱ;
    }

    public void ॱ(final chy o_chy) {
        this.ॱ = o_chy;
        ˊ().setOnClickListener(new evx(this) {
            final /* synthetic */ HorizonBaseCard ॱ;

            public void ˋ(View view) {
                o_chy.ˏ(9, this.ॱ);
            }
        });
    }

    protected void ॱ(CardBean cardBean) {
        ((TextView) this.ˊˋ.findViewById(d.ꜞ)).setText(cardBean.v_());
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        ॱ(cardBean);
        if (cardBean instanceof HorizonBaseBean) {
            HorizonBaseBean horizonBaseBean = (HorizonBaseBean) cardBean;
            this.ʼ.ॱ(horizonBaseBean.ˊ(), horizonBaseBean.ॱ());
        }
        this.ˎ.ˊ();
    }

    private void ˋ(View view, CSSRule cSSRule) {
        if (cSSRule != null) {
            CSSView.wrap(view, cSSRule).render();
        }
    }
}
